package StudentSys;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

@WebServlet("/Stuserlert01")
public class Stuserlert01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=UTF-8");
        ArrayList<Stu> stus = new ArrayList<>();
        BufferedReader bufferedReader = new BufferedReader(new FileReader("C:\\Users\\Admin\\Desktop\\1.txt"));
        String line;
        while ((line=bufferedReader.readLine())!=null){
            String[] split = line.split(",");
            Stu stu = new Stu(split[0],split[1],split[2]);
            stus.add(stu);
        }

        PrintWriter writer = resp.getWriter();
        for (int i = 0; i < stus.size(); i++) {
            writer.write(stus.get(i).getName()+","+stus.get(i).getAge()+","+stus.get(i).getChengji());
            writer.write("<br>");
        }
        writer.close();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
